/*
 * @Author: cygao
 * @Date: 2018-11-09 13:58:25
 * @Last Modified by: cygao
 * @Last Modified time: 2018-11-20 18:58:50
 * 评论板块
 */

import React, { Component } from 'react';
import { connect } from "react-redux";
import * as actions from '../../../../store/action/community';
import './comment.less'


class Comment extends Component{
    constructor(props) {
        super(props)
    }
    onLike(id){
        this.props.likeComment({
            cid: id
        })
        this.props.fetchFunList();
    }
    render() {
        return (
            <div>
            { this.props.comments.map((item, index) => {
            return <div className="comment-container clearfix">
                <div className="user">
                    <img className="avatar" src={item.user.avatar}/>
                    <div className="user-info">
                        <p className="name">{item.user.nickname}</p>
                        <p className="time">{item.created_at}</p>
                    </div>
                    <div className="like" onClick={this.onLike.bind(this, item.id)}>
                        <i className="icon icon-like"></i>
                        <span>{item.like_count}</span>
                    </div>
                </div>
                <div className="text">{item.content}</div>
            </div>
            })}
            </div>
        )
    }
}

export default connect((state)=>{return {...state}}, actions)(Comment);